﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ISODOC.Models.Request.DARDOC_DS>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit_ByUser
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table class="tftable" style="width: 95%">
        <tr style="background-color: #929097; color: White;">
            <td colspan="2">
                <h3>
                    DAR No.
                    <%: Model._Docno %></h3>
            </td>
        </tr>
        <tr>
            <th style="width: 30%">
                <h3>
                    ผู้ร้องขอ</h3>
            </th>
            <td>
                <%: Model._Empname %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ผู้จัดการแผนก.</h3>
            </th>
            <td>
                <%: Model._Mgrname %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ประเภทเอกสารและข้อมูล</h3>
            </th>
            <td>
                <%: Model._DOCTypenm %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    หัวข้ออนุมัติ</h3>
            </th>
            <td>
                <%: Model._OPTTypenm %>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    เอกสารที่ต้องการอนุมัติ</h3>
            </th>
            <td>
                <div id="attachment1">
                </div>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    รายละเอียด/เหตุผลของการอนุมัติ</h3>
            </th>
            <td>
                <textarea cols="75" rows="5" id="txtReason"><%:  Model._Text %></textarea>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    ระบุความสัมพันธ์กับเอกสารอื่น</h3>
            </th>
            <td>
            </td>
        </tr>
        <tr>
            <th>
                <h3>
                    Revision ก่อนหน้า</h3>
            </th>
            <td>
                <%: Model._Refrev %>
            </td>
        </tr>
    </table>
    <table class="tftable" style="width: 95%">
        <tr style="background-color: #929097; color: White;">
            <td colspan="2">
                <h3>
                    Your Message</h3>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <textarea id="txtMsg" cols="108" rows="5"></textarea>
            </td>
        </tr>
        <tr>
            <td style="border-right: 0px;">
                <input type="button" id="btnSend" value="Send" class="btn" style="width: 150px;" />
            </td>
            <td style="text-align: right; border-left: 0px;">
                <input type="button" id="btnReject" value="Reject" class="btn" style="width: 150px;" />
            </td>
        </tr>
    </table>
    <br />
    <%: Html.Partial("_History",Model) %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
    <h2>
        Edit_ByUser</h2>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
    <script src="<%: Url.Content("~/Scripts/telerik.common.min.js")%>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/telerik.upload.min.js")%>" type="text/javascript"></script>
    <script src="<%: Url.Content("~/Scripts/jquery.multiple.select.js")%>" type="text/javascript"></script>
    <link href="<%: Url.Content("~/Content/themes/telerik.comcustommon.min.css")%>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Content/themes/telerik.common.min.css")%>" rel="stylesheet"
        type="text/css" />
    <link href="<%: Url.Content("~/Content/themes/metro/telerik.metro.min.css")%>" rel="stylesheet"
        type="text/css" />
    <script type="text/javascript">
        $(function () {
            var attachments = [];
            attachments.push({
                fileName: '<%: Model._Filename %>',
                fileTempName: '<%: Model._FileTemp %>'
            });

            var upload1 = $("#attachment1").upload({ attachments: attachments, uploadUrl: '<%:Url.Action("Upload1") %>', downloadUrl: '<%:Url.Action("DownloadTemp") %>', multiple: false });
            $("a[fileTempName]").click(function () {
                var downloadUrl = '<%:Url.Action("Download") %>';
                var temp = $(this).attr("fileTempName");
                var file = $(this).text();
                var data = { fileName: file, fileTempName: temp };
                $.download(downloadUrl, data);
            });

            $("#btnSend").click(function () {
                var files = upload1.getFiles();
                if (files.length <= 0) {
                    $().toastmessage('showErrorToast', "ระบุเอกสารที่ต้องการอนุมัติ");
                    return false;
                }
                var editfile = files[0].edit;

                var dataForSubmit = new Array();
                dataForSubmit.push({
                    _Docno: '<%: Model._Docno %>',
                    _Filename: files[0].fileName,
                    _FileTemp: files[0].fileTempName,
                    _Text: $("#txtReason").html(),
                    _Refrev: $("#txtrev").val(),
                    //                          _Refdocid: $('#cboRevdoc').val(),
                    _Text: $("#txtReason").val()
                })
                var getUsersUrl = '<%= Url.Action("Edit_Req") %>'; WAITINGDLG_show(imgWait);
                callScriptMethod(getUsersUrl, { theData: dataForSubmit, fileedit: editfile, msg: $("#txtMsg").val() });
            });
            function callScriptMethod(url, jsonObject, action, callback, async) {

                callback = callback || function () { };
                async = (async == null || async);

                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: url,
                    data: JSON.stringify(jsonObject),
                    dataType: "json",
                    async: async,
                    success: function (data) {

                        if (data.success != "0") {
                            $().toastmessage('showSuccessToast', data.message);
                        } else $().toastmessage('showErrorToast', data.message);
                        WAITINGDLG_hide();
                    },
                    error: function (xhr, status, error) {
                        var err = xhr.responseText;
                        alert(err.Message);
                    }

                });
                // 
            }
        });

    </script>
</asp:Content>
